feat: add standalone Klarna widget component#455
Open
ArushKapoorJuspay wants to merge 2 commits into
Open
Conversation
- Add KlarnaWidget sdkState variant with dedicated KlarnaWidgetWrapper.res - Use wallet_name_str field in SessionsType for reliable Klarna session matching - Use nativePropRef pattern to avoid stale closure in processRequest - Wire up NavigationRouter, AllPaymentHooks, ErrorHooks, LoadingOverlay - Correct confirm body: pay_later.klarna_sdk.token (not wallet.*)
…ailability + INVOKE_SDK_CLIENT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a self-contained Klarna widget with a dedicated
KlarnaWidgetsdkState that wraps the existing<Klarna>component. The widget renders the Klarna SDK inline, handles payment authorization, and confirms via the payments API.Changes
New:
src/pages/widgets/KlarnaWidgetWrapper.res(+145 lines)<Klarna>componentreadyMessageon mount, receives credentials via native"widget"eventnativePropRefpattern to prevent stale closureswallet_name_strfield (notwallet_nameenum which mapped"klarna"toNONE)setLaunchKlarna(_ => Some("launch"))whenconfirm: truepay_later.klarna_sdk.tokenconfirm body →fetchAndRedirectaccountPaymentMethodDatacontext — findspayment_method_type == "klarna"isKlarnaAvailablememo gated onINVOKE_SDK_CLIENTpayment experience (only Klarna with SDK integration is supported)getRequiredFieldsForButtonfromDynamicFieldsContextbefore confirmPaymentUtils.generateCardConfirmBody+CommonUtils.mergeDictfor confirm body (canonical pattern)klarnaSessionToken !== ""ANDisKlarnaAvailablesrc/types/SdkTypes.res(+3 lines)KlarnaWidgettosdkStatevariant typeKlarnaWidgettosdkStateToStrMapper(returns"klarna")"klarna"case to sdkState parsersrc/types/AllApiDataTypes/SessionsType.res(+3/-1 lines)wallet_name_str: stringfield tosessionsrecord — stores raw wallet name string for reliable matching (the existingwallet_nameenum mapped"klarna"toNONE)defaultTokenanditemToObjMapperto include the new fieldsrc/routes/NavigationRouter.res(+1 line)KlarnaWidget => <KlarnaWidgetWrapper />routesrc/hooks/AllPaymentHooks.res(+1 line)KlarnaWidget => exitWidget(apiResStatus, "klarna")to success/failure handlersrc/utility/reusableCodeFromWeb/ErrorHooks.res(+2/-2 lines)KlarnaWidgetto 2 exhaustive switch statementssrc/components/elements/LoadingOverlay.res(+1/-1 line)KlarnaWidgetto loading overlay switchArchitecture Decision
This PR uses Approach A (dedicated
KlarnaWidgetsdkState) rather than Approach B (adding KLARNA to the wallet enum). Approach A scored 6/10 vs Approach B's 4/10 because:pay_latertype, NOT a wallet — adding it to the wallet enum would be semantically wrongwallet_name_str(raw string) since the enum maps"klarna"toNONEINVOKE_SDK_CLIENTpayment experience check is specific to Klarna — other wallet widgets use different experience typesData Flow
AllApiDataContextNew→sessionTokenData→ findwallet_name_str == "klarna"AllApiDataContextNew→accountPaymentMethodData→ findpayment_method_type == "klarna"isKlarnaAvailablechecks PML entry hasINVOKE_SDK_CLIENTinpayment_experienceDynamicFieldsContext→getRequiredFieldsForButton(paymentMethodData)PaymentUtils.generateCardConfirmBodymerged withpay_later.klarna_sdk.tokenviaCommonUtils.mergeDictWidget Communication Flow
Testing
npm run re:checkwith-warn-error +a-4-9)